/**
* Trigger Name: ifulfillRestrictDeleteWActivities
* Author: Accenture 
* Date: 03-Feb-2012 
* Requirement/Project Name: iFulfill 
* Requirement Description: Workflow Activity cannot be deleted if  it is reffrenced in workflow definition which is not in Inactive 
**/


trigger ifulfillRestrictDeleteWActivities on Workflow_Activities__c (before delete)
{

list<Workflow_Stage__c> wfstageList = new list<Workflow_Stage__c>();
list<Workflow_Definition__c> wfdefinitionList = new list<Workflow_Definition__c>();
list<Wokflow_Steps__c> wfstepList = new list<Wokflow_Steps__c>();


Set<ID> wfId = new Set<Id>(); 
for(Workflow_Activities__c f: trigger.old) 
{     
wfId.add(f.Step_Name__c); 
} 

  
        wfstepList =[select id from Wokflow_Steps__c where Wokflow_Stage_Name__r.Workflow_Code__r.status__c !='Inactive'];
    
                
 wfId.clear(); 
 for(Wokflow_Steps__c wfObj: wfstepList) 
 {     
 wfId.add(wfObj.id); 
 }   
 for(Workflow_Activities__c f: trigger.old) 
 {     
  if(wfID.contains(f.Step_Name__c))      
  {            
  f.adderror('Workflow Activity cannot be deleted if  workflow definition is not in Inactive status');      
  }  
  }
}